grammar CSS3X;

options 
{
	output=AST ;
	language=CSharp3 ;
}

tokens {
	ATTBEGINSWITH;
	ATTEQUAL;
	ATTCONTAINS;
	ATTENDSWITH;
	ATTHASVAL1;
	ATTHASVAL2;
	
	ELEMENTCLASS;
	ELEMENTNAME;
	ELEMENTID;
}

stylesheet
	:
		charset?
	;

charset
	:
		'@charset' WS+ STRING
	;

attribute
	: '[' IDENT ( attributeRelation (STRING | IDENT) )? ']'
	;

attributeRelation
	: '='  -> ATTEQUAL
	| '~=' -> ATTHASVAL1
	| '|=' -> ATTHASVAL2
	| '^=' -> ATTBEGINSWITH
	| '$=' -> ATTENDSWITH
	| '*=' -> ATTCONTAINS
	;
	
element
	: ( IDENT? elementClass* elementId? elementClass* ) -> ^( ELEMENTNAME ELEMENTCLASS* ELEMENTID? ELEMENTCLASS* ) 
	;

elementClass
	: '.' IDENT -> ^( ELEMENTCLASS IDENT )
	;

elementId
	: '#' IDENT -> ^( ELEMENTID IDENT )
	;

MultiLineComment
	: '/*' ( options { greedy = false; } : . )* '*/' { $channel = Hidden; }
	;


IDENT
	:	('_' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' ) 
		('_' | '-' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' | '0'..'9')*
	|	'-' ('_' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' ) 
		('_' | '-' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' | '0'..'9')*
	;

STRING
	:	'"'! (~('"'|'\n'|'\r'))* '"'!
	|	'\''! (~('\''|'\n'|'\r'))* '\''!
	;


WS  :   ( ' '
        | '\t'
        | '\r'
        | '\n'
        ) {$channel=HIDDEN;}
        ;


